<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ItemEditor
 *
 * @author root
 */
class App_forms_ItemEditor extends Zend_Form {
    
    public function __construct($itemId, $session, $mode = "create") {
        $this->name = new Zend_Form_Element_Text('name');
        $this->name->setLabel('Item Name:')
             ->setrequired(true);
        
        $this->description = new Zend_Form_Element_Textarea("description");
        $this->description->setLabel('Description:')
             ->setrequired(true);
        
        $this->id = new Zend_Form_Element_Hidden('id');
        $this->id->setValue($itemId);
        
        if (array_key_exists($itemId, $session->items)){
            $this->MapItemToForm($session->items[$itemId]);
        
            echo "====";
        }
        
        $this->submit =  new Zend_Form_Element_Submit($mode);
        
        $this->addElements(array(
            $this->name,
            $this->id,
            $this->description
        ));
        
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl')),
            'Form'
        ));
     
     
     
    }
    
    public function MapItemToForm(App_ItemDto $item){
        $this->name->setValue($item->name);
        $this->description->setValue($item->description);
        $this->id->setValue($item->id);
    }

    

    public function MapFormToItemDto(){
       
        return new App_ItemDto(
                $this->name->getValue(),
                $this->description->getValue(),
                $this->id->getValue()
            );
    }
}

?>
